 <template>
    <div class="l-right">
        <el-form :inline="true" :model="npcTaskForm" class="demo-form-inline add-form" label-width="90px">
            <el-form-item label="采购组织：">
                <el-select v-model="npcTaskForm.purOrgId" placeholder="请选择" @change="handleChange">
                    <el-option v-for="item in purOrgOptions" :key="item.id" :label="item.purOrgName" :value="item.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="采购组:">
                <el-select v-model="npcTaskForm.purGroupId" placeholder="请选择">
                    <el-option v-for="item in relationPurGroup" :key="item.id" :label="item.purGroupName" :value="item.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="工厂:">
                <el-select v-model="npcTaskForm.factoryId" placeholder="请选择" @change="handleFactoryChange">
                    <el-option v-for="item in relationFactory" :key="item.id" :label="item.factoryName" :value="item.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="打样类型:">
                <el-select v-model="npcTaskForm.npcType" placeholder="请选择">
                    <el-option v-for="item in npcTypes" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="任务名称：">
                <el-input v-model="npcTaskForm.taskName"></el-input>
            </el-form-item>
            <el-form-item label="品类:">
              <select-tree :multiple="false" ref="selectTree" v-model="npcTaskForm.categoryName" :code.sync="npcTaskForm.categoryCode"></select-tree>
            </el-form-item>
            <el-form-item label="接收岗位：" prop="sysStationName">
                 <select-station v-model="npcTaskForm.sysStationName" :name="'stationName'" ref="selectStation" @on-selection-data="getRowData"></select-station >
            </el-form-item>
            <el-form-item label="邮件/短信提醒：" label-width="120px" prop="shortMessage">
                <el-radio-group v-model="npcTaskForm.shortMessage">
                    <el-radio label="1">是</el-radio>
                    <el-radio label="0">否</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="附件上传：" class="upload">
            <el-upload
                class="upload-file"
                ref="upload"
                :action="this.lib.config.host.system + '/common/fileupload/upload'"
                :data=fileData
                :limit="1"
                :on-success="uploadSuccess"         
                :file-list="fileList">
                <el-button slot="trigger" type="primary">选取文件</el-button>
            </el-upload>
            </el-form-item>
            <el-form-item label="备注：" prop="name" class="w100">
                <UE v-model="npcTaskForm.notice" :config="config" ref="ue"></UE>
            </el-form-item> 
        </el-form>
    </div>
</template>
<script>
    import UE from '@/components/common/ue/ue.vue';
    import SelectTree from '@/components/common/select-ext/select-tree.vue';
    import SelectStation from '@/components/common/select-ext/select-station.vue';  
    export default {
        components: {
            UE,
            SelectTree,
            SelectStation
        },
        data() {
            return {
                // 采购组织集合
                purOrgOptions:[],
                // 采购组集合
                relationPurGroup: [],
                // 工厂集合
                relationFactory: [],
                // 打样类型
                npcTypes: [],
                formLabelWidth: '200px',
                fileList: [],
                // 定义附件的业务模块和业务动作
                fileData: {
                    busAction: "ADD",
                    tableName: "NPC_TASK"
                },
                config: {
                    initialFrameWidth: 1450,
                    initialFrameHeight: 200,
                    enableAutoSave: false
                 },
            };
        },
        props:['npcTaskForm'],
        created(){
            this.handleChange(this.npcTaskForm.purOrgId)
            this.handleFactoryChange(this.npcTaskForm.factoryId);
        },
        mounted() {
            this.initData();
        },
        // 监听品类下拉
        watch: {
        'npcTaskForm.categoryName':function(val){
            let data = this.$refs['selectTree'].getResultData();
            if(!!data.id){
            this.npcTaskForm.categoryId = data.id;
            }
        }
        },
        methods: {
            initData(){
                // 获取采购组织
                this.getSelectData('get', this.lib.config.host.masterData + '/system/purOrgMgt/purOrg/getPurOrgByUserId/' + this.getCurrUserId(), {}, 'id', 'purOrgName').then((data)=>{
                    this.purOrgOptions = data;
                });
                // 查询打样类型
                this.getDicData('DLV_FLOW').then((data)=>{
                    this.npcTypes = data;
                });
            },
            // 采购组织在改变的时候查询采购组
            handleChange(value) {
                // 获取srm采购组
                this.getSelectData('post', this.lib.config.host.masterData + '/mdata/purOrgMgt/purGroup/getByPurOrgId/' + value, {}, 'id', 'purGroupName').then((data)=>{
                    this.relationPurGroup = data;
                });
                // 获取采购组织对应的工厂
                this.getSelectData('post', this.lib.config.host.masterData + '/system/factoryMgt/factorys/getFactoryByPurId/' + value, {}, 'id', 'factoryName').then((data)=>{
                    this.relationFactory = data;
                });
                // 把子组件的值发射至父组件
                this.$emit('changePurOrg', value);
            },
            // 工厂下拉改变时触发
            handleFactoryChange(value) {
                // 把子组件的值发射至父组件
                this.$emit('changeFactory', value);
            },   
            handleExceed(files, fileList){
                console.log(files);
                console.log(fileList);
            },
            // 自动上传附件后返回附件url和name
            uploadSuccess: function (response) {
                //附件上传成功回调
                this.npcTaskForm.attachmentUrl = response.url;
                this.npcTaskForm.attachmentName = response.fileName
            },
            getUEContentTxt() {
                let content = this.$refs.ue.getUEContentTxt(); // 调用子组件方法
                return content;
            },
            // 双击选中行，触发事件
            getRowData(data){
                this.npcTaskForm.sysStationId = data.id;
                this.npcTaskForm.sysStationName = data.stationName;
            },
        }
  };
</script>
<style>

</style>